
import com.thelab.ui.*;


dynamic class com.thelab.ui.Track extends UIElement
{	
	
	var _direction:String;
	var onRatio:Function;
	
	public function Track(scope:MovieClip,px:Number,py:Number,size:Number,direction:String)
	{
		super("UITrack",scope);
		target._x = px || 0;
		target._y = py || 0;
		style.size = size || 100;
		style.linecolor = 0x333333;
		style.linethick = 3;
		_direction = direction || "right";
		draw();
	}	
	
	private function setEvents()
	{
		target.onRelease = function()
		{	
			var ref:MovieClip = this;
			var base =ref.__base;
			
			var s:Number = base.style.size;
			var xm:Number = base.target._xmouse;	xm = (xm<0)?-xm:xm;
			var ym:Number = base.target._ymouse;	ym = (ym<0)?-ym:ym;
			var r:Number = (xm<ym)?(ym/s):(xm/s);	
			
			var elapsed:Number = getTimer() - base.dc_clock;
			if(elapsed <= base.dc_time)
			{
				base.onDoubleClick(base,r);
				base.dc_clock = getTimer();
			}
			else
			{
				
				base.onClick(base,r);
				base.dc_clock = getTimer();
			}			
			ref.onEnterFrame = undefined;
		}
	}

	
	function draw()
	{
		var s:Number = style.size;
		target.clear();
		target.lineStyle(style.linethick,style.linecolor,style.linealpha);
		target.beginFill(style.backcolor,style.backcolor);
		switch(_direction)
		{
			case "up":   { line(0,0,0,-s); break;	}
			case "down": { line(0,0,0,s);  break;	}
			case "left": { line(0,0,-s,0); break;	}
			case "right":{ line(0,0,s,0);  break;	}
		}
		target.endFill();		
	}
	
	
}
